#include <stdio.h>
#include <string.h>

	double	h[100002];
	long	seq[100002];
	long	n;
	double	best;

main()
{
	long	i,j,k;
	long	l,r;

	while (scanf("%ld",&n),n>0)
	{
		best=0;
		for (i=1;i<=n;i++)
			scanf("%lf",h+i);
		h[0]=h[n+1]=-1;
		seq[0]=seq[n+1]=-1;

		for (i=1;i<=n;i++)
		{
			j=i;
			while (h[i]<=h[j-1])
				j=seq[j-1];
			seq[i]=j;
		}

		/*/debug
		printf("  ");
		for (i=1;i<=n;i++)
			printf("%ld ",seq[i]);
		printf("\n");
		//debug*/

		best=-10000;

		for (i=n;i>0;i--)
		{
			j=i;
			while (h[i]<=h[j+1]) 
				j=seq[j+1];
			if ((j-seq[i]+1)*h[i] > best)
				best=(j-seq[i]+1)*h[i];
			seq[i]=j;
		}
		/*/debug
		for (i=1;i<=n;i++)
			printf("%ld ",seq[i]);
		printf("\n");
		//debug*/
		
		printf("%0.0lf\n",best);
	}
	return 0;
}	
